
from google.appengine.ext import endpoints
from google.appengine.ext import ndb


class BusinessInfo(ndb.Model):
    user = ndb.UserProperty(required=True, indexed=True)
    name = ndb.StringProperty(required=True)
    business_name = ndb.StringProperty(required=True)
    email = ndb.StringProperty()
    phone_number = ndb.StringProperty()
    address = ndb.StringProperty()
    notification_message = ndb.StringProperty(required=True)
    notification_time = ndb.IntegerProperty(required=True)
    blocked_numbers = ndb.StringProperty(repeated=True)
    calendarId = ndb.StringProperty()
    last_updated = ndb.IntegerProperty(required=True)
    access_token = ndb.StringProperty()
    refresh_token = ndb.StringProperty()
    token_expires = ndb.DateTimeProperty(default=None)
    gcd_id = ndb.StringProperty()


class Customer(ndb.Model):
    user = ndb.UserProperty(required=True, indexed=True)
    name = ndb.StringProperty(required=True)
    phone_number = ndb.StringProperty(required=True, indexed=True)
    deleted = ndb.BooleanProperty(required=True)
    email = ndb.StringProperty()
    address = ndb.StringProperty()
    last_updated = ndb.IntegerProperty(required=True)


class Appointment(ndb.Model):
    user = ndb.UserProperty(required=True)
    customer = ndb.KeyProperty()
    title = ndb.StringProperty()
    start_time = ndb.IntegerProperty(required=True)
    timezone = ndb.StringProperty()
    duration = ndb.IntegerProperty(required=True)
    confirmation_status = ndb.IntegerProperty(required=True)
    confirmation_time = ndb.IntegerProperty()
    notification_time = ndb.IntegerProperty()
    notes = ndb.TextProperty(required=True)
    repeated = ndb.IntegerProperty()
    deleted = ndb.BooleanProperty(required=True)
    remote_id = ndb.StringProperty()
    short_url = ndb.StringProperty()
    last_updated = ndb.IntegerProperty(required=True)
    confirmation_token = ndb.StringProperty(required=True)

    def get_url(self):
        return "http://showup-app.appspot.com/confirm/%d/%s" % (self.key.id(), self.confirmation_token)